package gbench.appdemo.myworld.market.store;

import java.text.MessageFormat;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

import gbench.appdemo.myworld.market.commodity.Commodity;
import gbench.appdemo.myworld.market.commodity.Price;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * 商品西悉尼
 * @author gbench
 *
 */
@Data @AllArgsConstructor
public class CommodityQuotation{
    
    /**
     * 
     * @param name 商品名称
     * @param quantity 商品数量
     * @param price 商品价格
     */
    public CommodityQuotation(String name,Double quantity,Price<Commodity,Commodity> price){
        this.initialize(name, quantity, price);
        this.commodity = price.getB();
    }
    
    /**
     * 初始化
     * @param name
     * @param quantity
     * @param price
     */
    public void initialize(String name,Double quantity,Price<Commodity,Commodity> price) {
        this.name = name;
        this.quantity = quantity;
        this.price = price;
        this.keywords.add(this.name);
    }
    
    /**
     * 可用数量
     * @return
     */
    public Double getAvailable() {
        return quantity-freezed-released;
    }
    
    /**
     * 
     */
    public String toString() {
        return MessageFormat.format("{0}\tavailable:{1},quantity:{2},freezed:{3},freezed:{4}", 
            this.name,
            this.getAvailable(),this.quantity,this.freezed,this.released);
    }
    
    private String code = UUID.randomUUID().toString();// 商品代码
    private String name; // 商品名称
    private Double quantity=0d; // 入库数量
    private Double freezed=0d; // 冻结数量
    private Double released=0d; // 出库数量
    private CommodityStatus status = CommodityStatus.ENABLED; // 商品状态
    private Price<Commodity,Commodity> price;
    private List<String> keywords = new LinkedList<>();// 商品分类
    private Commodity commodity;
    private AtomicInteger version = new AtomicInteger(0);// 报价单版本
    
    /**
     * 商品摘要状态
     * @author gbench
     *
     */
    public enum CommodityStatus{
        ENABLED,
        DISABLED,
    };
    
}